]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
parentalControlsManager: Add more helper methods
authorPhilip Withnall <pwithnall@gnome.org>
Thu, 20 Nov 2025 16:32:18 +0000 (16:32 +0000)
committerPhilip Withnall <pwithnall@gnome.org>
Thu, 20 Nov 2025 18:29:27 +0000 (18:29 +0000)
For working out whether any parental controls apply to the current user.
These will be used in an upcoming commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3968>

js/misc/parentalControlsManager.js

index f4b284120bb5bd7048022a4e13e242945433d1ee..267c37e5a3b7de826064eb688293adb1d6002917 100644 (file)
@@ -60,6 +60,12 @@ const ParentalControlsManager = GObject.registerClass({
         'app-filter-changed': {},
         'session-limits-changed': {},
     },
+    Properties: {
+        'any-parental-controls-enabled': GObject.ParamSpec.boolean(
+            'any-parental-controls-enabled', null, null,
+            GObject.ParamFlags.READABLE,
+            false),
+    },
 }, class ParentalControlsManager extends GObject.Object {
     _init() {
         super._init();
@@ -78,6 +84,7 @@ const ParentalControlsManager = GObject.registerClass({
             this._initialized = true;
             this.emit('app-filter-changed');
             this.emit('session-limits-changed');
+            this.notify('any-parental-controls-enabled');
             return;
         }
 
@@ -101,6 +108,7 @@ const ParentalControlsManager = GObject.registerClass({
         this._initialized = true;
         this.emit('app-filter-changed');
         this.emit('session-limits-changed');
+        this.notify('any-parental-controls-enabled');
     }
 
     async _getAppFilter() {
@@ -131,6 +139,7 @@ const ParentalControlsManager = GObject.registerClass({
         try {
             this._appFilter = await this._getAppFilter();
             this.emit('app-filter-changed');
+            this.notify('any-parental-controls-enabled');
         } catch (e) {
             // Log an error and keep the old app filter.
             logError(e, `Failed to get new MctAppFilter for uid ${Shell.util_get_uid()} on app-filter-changed`);
@@ -165,6 +174,7 @@ const ParentalControlsManager = GObject.registerClass({
         try {
             this._sessionLimits = await this._getSessionLimits();
             this.emit('session-limits-changed');
+            this.notify('any-parental-controls-enabled');
         } catch (e) {
             // Keep the old session limits
             logError(e, `Failed to get new MctSessionLimits for uid ${Shell.util_get_uid()} on session-limits-changed`);
@@ -201,6 +211,30 @@ const ParentalControlsManager = GObject.registerClass({
         return this._appFilter.is_appinfo_allowed(appInfo);
     }
 
+    /**
+     * Check whether parental controls app filtering is enabled for the account,
+     * and if the library supports the features required for the functionality.
+     *
+     * Typically you should check whether a certain app is filtered
+     * (shouldShowApp()), rather than checking whether filtering is enabled at
+     * all.
+     *
+     * @returns {bool} whether app filtering is supported and enabled.
+     */
+    appFilterEnabled() {
+        // Are latest parental controls enabled (at configure or runtime)?
+        if (!HAVE_MALCONTENT_0_14 || this._disabled)
+            return false;
+
+        // Have we finished initialising yet?
+        if (!this.initialized) {
+            console.debug('Ignoring app filter because parental controls not yet initialised');
+            return false;
+        }
+
+        return this._appFilter.is_enabled();
+    }
+
     /**
      * Check whether parental controls session limits are enabled for the account,
      * and if the library supports the features required for the functionality.
@@ -220,4 +254,14 @@ const ParentalControlsManager = GObject.registerClass({
 
         return this._sessionLimits.is_enabled();
     }
+
+    /**
+     * Whether any parental controls are supported and enabled for the current
+     * user.
+     *
+     * @type {bool}
+     */
+    get anyParentalControlsEnabled() {
+        return this.appFilterEnabled() || this.sessionLimitsEnabled();
+    }
 });